package com.central.apps.handler;

import com.central.app.common.base.BaseHandler;
import com.central.app.service.HandlerService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Component
@Slf4j
public class SupplierAccountHandler extends BaseHandler {
    @Autowired
    private HandlerService handlerService;
    public  void SupplierAccount() throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String suppype ="黑名单";
        String suppype1="名录外";
        List<Map<String, Object>> bySql = handlerService.findBySql("select exblacklist,id from gq_account where suppype='" + suppype + "'");
        if (CollectionUtils.isNotEmpty(bySql)){
            for (int i=0;i<bySql.size();i++){
                Map<String, Object> map = bySql.get(i);
                String exblacklist = MapUtils.getString(map, "exblacklist");
                String id = MapUtils.getString(map, "id");
                Date parse = sdf.parse(exblacklist);
                if (date.after(parse)){
                    handlerService.updateBySql("update gq_account set suppype ='"+suppype1+"' where id='"+id+"'");
                }
            }
        }
    }
}
